package config

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type Db struct {
	Dbname   string `json:"dbname" yaml:"dbname"`
	Host     string `json:"host" yaml:"host"`
	Port     int    `json:"port" yaml:"port"`
	Username string `json:"username" yaml:"username"`
	Password string `json:"password" yaml:"password"`
	Charset  string `json:"charset" yaml:"charset"`
}

type AllConfig struct {
	Env   string `yaml:"env"`
	Mysql Db     `yaml:"mysql"`
}

func GetConfigs() AllConfig {
	config, err := ioutil.ReadFile("./config/go.yaml")
	if err != nil {
		log.Fatal(err)
	}
	var allConfig AllConfig
	err = yaml.Unmarshal(config, &allConfig)
	if err != nil {
		log.Fatal("db配置读取失败")
	}
	fmt.Println(allConfig)
	return allConfig
}

/**
 * 当前环境
 */
func GetEnvironment() string {
	return GetConfigs().Env
}
